package com.hrzyit.whistle.cases.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.baidu.mapapi.search.core.PoiInfo
import com.hrzyit.base.ui.adapter.BaseRecyclerViewAdapter
import com.hrzyit.whistle.cases.R
import kotlinx.android.synthetic.main.activity_location_map.view.*
import kotlinx.android.synthetic.main.item_location_map.view.*

/**
 * 百度地图 PoiInfo 适配器
 * @author YangWei
 * @date 2019/3/29
 */
class LocationMapListAdapter(context: Context) :
    BaseRecyclerViewAdapter<PoiInfo, LocationMapListAdapter.ViewHolder>(context) {

    /**
     * 创建视图持有者，并返回 View
     */
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext)
            .inflate(R.layout.item_location_map, parent, false)

        return ViewHolder(view)

    }

    /**
     * 绑定视图组件数据及事件
     */
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        super.onBindViewHolder(holder, position)

        val model = dataList[position]

        holder.itemView.mLocationAddressTv.text = model.address

//        var iconDrawable = ContextCompat.getDrawable(mContext, iconDrawableId)
//        holder.itemView.mCaseTypeIconIv.setImageDrawable(iconDrawable)

        // 注册列表项事件
        holder.itemView.mLocationAddressTv.setOnClickListener {
            mItemClickListener!!.onItemClick(it, model, position)
        }
    }


    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}